# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=qt6-languageserver
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
_qtver=6.9.0
pkgver=${_qtver/-/}
pkgrel=1
pkgdesc='Qt Language Server (mingw-w64)'
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qt.io'
msys2_repository_url="https://code.qt.io/cgit/qt/qtlanguageserver.git"
msys2_references=(
  'archlinux: qt6-languageserver'
  "cpe: cpe:/a:qt:qt"
)
license=('spdx:LGPL-3.0-only WITH Qt-GPL-exception-1.0 AND BSD-3-Clause AND GFDL-1.3-no-invariants-only AND GPL-2.0-only AND GPL-3.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-qt6-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-qt6-base")
groups=("${MINGW_PACKAGE_PREFIX}-qt6")
_pkgfn="${_realname/6-/}-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/${_qtver}/submodules/${_pkgfn}.tar.xz")
sha256sums=('eee65e036152eee36b63127013fb8e4f0cbbde66bae5f88864b56b70e357492e')

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    --log-level=STATUS \
    -GNinja \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_pkgfn}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install build-${MSYSTEM}

  install -d "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $_pkgfn/LICENSES/* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
